# -*- coding=utf-8 -*-
from HQAPI import CTPMarket,MD_NEWTICK,MD_LOGIN_SCUESS
import time
import datetime


def main():
    market = CTPMarket()
    #DATA0=market.Subcribe('jm1801')
    time.sleep(3)
    
    
    #
    while(True):
        m_new_tick_event = market.OnEvent() # 如果没有新tick程序将会阻塞在此，不继续运行
        if m_new_tick_event == MD_NEWTICK:          
            Instrument = market.Get_Tick_Name() #获取是哪个合约发来的新的tick
            print('Instrument',Instrument)
            if Instrument == 'jm1801':  #统一不要小b
               LastPrice = DATA0.LastPrice
               volm =DATA0.Volume
               UpdateMillisec = DATA0.UpdateMillisec
               print( 'Instrument:',Instrument,'volm:',volm,'LastPrice:',LastPrice,'UpdateMillisec:',UpdateMillisec,'ticktm:' , DATA0.UpdateTime,'time:',datetime.datetime.now())
           
        if m_new_tick_event == MD_LOGIN_SCUESS:
            # 订阅合约时，请注意合约的大小写，中金所和郑州交易所是大写，上海和大连期货交易所是小写的
            DATA0=market.Subcribe('jm1801')#  统一不要小b
            time.sleep(2)
        


if __name__ == '__main__':
    main()
